﻿/**
 *	html/pem_west.js
 *
 *	(C) 2014 Yuanjj
 *
 * 	history:
 * 		2014-07-07		create the file
 */

/**
 *	create west tree panels
 *
 *	@panel_west		[in] the west panel object
 */
function _create_subpanel_for_west( panel_west )
{
    var tree_panel_monitor		= _create_tree_panel_monitor( );
    var tree_panel_security		= _create_tree_panel_security( );
    var tree_panel_option		= _create_tree_panel_option( );
    var tree_panel_alarm		= _create_tree_panel_alarm( );
    var tree_panel_system		= _create_tree_panel_system( );

    panel_west.add_subpanel( tree_panel_monitor );
    panel_west.add_subpanel( tree_panel_security );
    panel_west.add_subpanel( tree_panel_option );
    panel_west.add_subpanel( tree_panel_alarm );
    panel_west.add_subpanel( tree_panel_system );

    panel_west.show_subpanel = tree_show_subpanel;
}

/**
 *	create the envirement monitor tree panel
 *
 *	return
 *		the tree panel object
 */
function _create_tree_panel_monitor( )
{
    var tree_panel_monitor = new Ext.tree.Panel
    ({
         id:"tree_panel_monitor",
         useArrows:true,
         listeners:{select:on_tree_panel_select},
         root:{
             id:"root", text:"环境监测", expanded:true,
             children:[
                 { id:"themometor",		text:"温度", 		leaf:true },
                 { id:"hygrometer", 	text:"湿度", 		leaf:true },
                 { id:"anemograph",	 	text:"风速", 		leaf:true },
                 { id:"sf6", 			text:"SF6", 		leaf:true },
                 { id:"light", 			text:"智能灯光控制",	leaf:true },
                 { id:"smoke", 			text:"消防烟感",		leaf:true },
                 { id:"guard", 			text:"门禁",			leaf:true }
             ]
         }
    });

    return tree_panel_monitor;
}

/**
 *	create security tree panel
 *
 *	return:
 *		the security tree panel object
 */
function _create_tree_panel_security( )
{
    var tree_panel_security = new Ext.tree.Panel
    ({
         id:"tree_panel_security",
         wdith:"100%",
         height:"100%",
         useArrows:true,
         listeners:{select:on_tree_panel_select},
         root:{
             id:"root", text:"安防监控", expanded:true,
             children:[
                 { id:"infrared", 		text:"主动红外对射报警", 	leaf:true },
                 { id:"dbinfrared", 	text:"红外双鉴探测", 		leaf:true },
                 { id:"e_fence", 		text:"电子围栏", 			leaf:true },
                 { id:"wetness_probe", 	text:"水浸探头", 			leaf:true }
             ]
         }
    });

    tree_panel_security.hide();

    return tree_panel_security;
}

/**
 *	create option tree panel
 *
 *	return:
 *		the option tree panel object
 */
function _create_tree_panel_option( )
{
    var tree_panel_option = new Ext.tree.Panel
    ({
         id:"tree_panel_option",
         wdith:"100%",
         height:"100%",
         useArrows:true,
         listeners:{select:on_tree_panel_select},
         root:{
             id:"root", text:"配置管理", expanded:true,
             children:[
                 { id:"scene", 		text:"场景设置", 		leaf:true },
                 { id:"tunnel", 	text:"通道管理", 		leaf:true },
                 { id:"protocal", 	text:"设备规约管理", 	leaf:true },
                 { id:"device", 	text:"设备配置", 		leaf:true },
                 { id:"collect",	text:"采集配置管理", 	expanded:true, children:[
                         { id:"switch", 	text:"开关量配置", 	leaf:true },
                         { id:"analogue", 	text:"模拟量配置", 	leaf:true },
                         { id:"interval", 	text:"采集时间配置",	leaf:true }
                     ]},
                 { id:"report", 	text:"上报配置管理",	leaf:true }
             ]
         }
    });

    tree_panel_option.hide();

    return tree_panel_option;
}

/**
 *	create the alarm tree panel
 *
 *	return
 *		the alarm tree panel object
 */
function _create_tree_panel_alarm( )
{
    var tree_panel_alarm = new Ext.tree.Panel
    ({
         id:"tree_panel_alarm",
         wdith:"100%",
         height:"100%",
         useArrows:true,
         listeners:{select:on_tree_panel_select},
         root:{
             id:"root", text:"事件与报警设置", expanded:true,
             children:[
                 { id:"threshold",		text:"报警联动设置", 		leaf:true },
                 { id:"event",	 		text:"事件查询", 			leaf:true }
             ]
         }
    });

    tree_panel_alarm.hide();

    return tree_panel_alarm;
}

/**
 *	create the system tree panel
 *
 *	return
 *		the system tree panel object
 */
function _create_tree_panel_system( )
{
    var tree_panel_system = new Ext.tree.Panel
    ({
         id:"tree_panel_system",
         wdith:"100%",
         height:"100%",
         useArrows:true,
         listeners:{select:on_tree_panel_select},
         root:{
             id:"root", text:"系统设置", expanded:true,
             children:[
                 { id:"host", text:"主机设置", leaf:true },
             ]
         }
    });

    tree_panel_system.hide();

    return tree_panel_system;
}

/**
 *	call back for monitor tree panel click
 *
 *	@node		[in] the tree node object
 *	@event		[in] the event
 */
function on_tree_panel_select( node, event )
{
    g_panel_main.panel_monitor.panel_center.show_subpanel( this.id, event.data.id, event.data.text );
}

/**
 *	show tree panel
 *
 *	@treeid			[in] the tree panel id
 */
function tree_show_subpanel( treeid )
{
    var treenode = undefined, nodeid = undefined, nodetext = undefined;

    // check the panel visible
    if ( undefined !== this.subpanel[treeid] && this.subpanel[treeid].isVisible() )
        return;

    // hide all tree panel
    for ( i in this.subpanel )
        this.subpanel[i].hide();

    // show the specific panel
    this.subpanel[treeid].show();

    // get the selected node
    treenode = this.subpanel[treeid].getSelectionModel().getLastSelected();
    if ( undefined === treenode )
        treenode = this.subpanel[treeid].getRootNode();

    nodeid		= treenode.data.id;
    nodetext 	= treenode.data.text;

    // show the center panel
    g_panel_main.panel_monitor.panel_center.show_subpanel( treeid, nodeid, nodetext );
}
